<?php
/**
 * Created by PhpStorm.
 * User: 江清月近人
 * Date: 2021/11/18
 * Time: 10:49
 */
namespace app\api\controller;

use app\admin\model\Corporates as cmodel;
use app\admin\model\GoodsLabel;
use app\common\controller\Api;
use app\admin\model\GoodsCate;
use app\admin\model\Store;
use think\Env;
use think\Db;
use app\admin\model\Corporates;
use app\admin\model\GoodsOrder;
class Corporate extends api
{ 
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];


    //商品列表
    public function list(){
        $model = new cmodel();
        $list = $model->where(['status_switch'=> 1 ,'type'=> 1])
            ->field('id,image,title,content,price')
            ->select();
       if (!empty($list)){
           return $this->success('获取成功',$list);
       }
     }
    //商城分类
    public function cate()
    {
        $cate = GoodsCate::where(['weigh' => 1, 'status' => 1])
            ->field('id,name,image')
            ->select();
        if (!empty($cate)) {
            foreach ($cate as &$v) {
                $v['image'] = Env::get('app.yuming') . $v['image'];
                $v->unsetAppend();
            }
        }
    }
    //门店信息
    public function store()
    {
        $store = Store::where(['weigh' => 1, 'status' => 1])
            ->field('id,name,address,number,time')
            ->select();
        if (!empty($store)) {
            return $this->success('获取成功', $store);
        }
    }
    //商品详情
    public function core(){
        $id = input('id');
        if (empty($id)) {
            $this->error('参数错误，传入商品id');
        }
        $corporates = CorporatesModel::field('id,image,price,,title,content,cate_id')
            ->find($id);
        $value = GoodsLabel::where('id', 'in', $corporates['label_id'])
            ->field('id,name,spe_id')
            ->select();
        $sku = [];
        foreach ($value as $vv) {
            $sku[$vv['spe_id']]['name'] = $vv['sku']['name'];
            unset($vv['sku']);
            $sku[$vv['spe_id']]['values'][] = $vv;
        }
        $corporates['label_id'] = $sku;
        $image = explode(',', $corporates['image']);
        $domain = [];
        foreach ($image as $vvv) {
            $domain[] = Env::get('app.yuming') . $vvv;
        }
        $corporates['image'] = $domain;
        $corporates['content'] = get_img_thumb_url($corporates['content']);
        $corporates->unsetAppend();
        $this->success('获取成功', $corporates);
    }
}

